$(function(){
	$("#userInfo").on("swiperight",function(){
		$("#controlPanel").panel("open");
	});
});

$(function(){
	$("#choosePro").click(function(){
		$("#portrait").click();
	});
});

$(function(){
	$("#portrait").change(function(){
		var file=$("#portrait").get(0).files[0];
	    var reader=new FileReader();
	    reader.onloadend=function (){
	        var dataURL = reader.result;
	        var img = $("#showPro")[0];
	        img.src = dataURL;// 插入到 DOM 中预览
	    };
	    reader.readAsDataURL(file); // 读出 base64
	});
});

$(function(){
	var skillClass=$("#skillClass");
	$("#yes").click(function(){
		skillClass.show("normal");
	});
	$("#no").click(function(){
		skillClass.hide("normal");
	});
});

var theUser;
$(function(){
	theUser=$.cookie("userId");
});

$(function(){
	$.ajax({
		type:"POST",
		url:"http://123.207.114.241/fishCow/php/selectUser.php",
		dataType:"json",
		data:{
			id:theUser
		},
		success:function(x,y,z){
			$("#username").html(x.nenufish_user_name);
			$("#nickname").val(x.nenufish_user_name);
			
			console.log(x)
		},
		error:function(jqXHR){
		    alert("发生错误:"+jqXHR.status);
		}
	});
});

$(function(){
	var backtaskForm=$("#backtaskForm");
	var backwaitpay=$("#backwaitpay");
	$("#allTasks a").click(function(){
		backtaskForm.show(100);
		backwaitpay.hide(100);
	});
	$("#waitpayList a").click(function(){
		backtaskForm.hide(100);
		backwaitpay.show(100);
	});
});

$(function(){
	$("#allTasks li").click(function(){
		var type=$(this).html();
		var phpUrl;
		if(type=="全部任务"){
			phpUrl="selectAllTask.php";
		}else if(type=="待确认"){
			phpUrl="selectUnconfirmTask.php";
		}else if(type=="待完成"){
			phpUrl="selectDoingTask.php";
		}else if(type=="待付款"){
			phpUrl="selectUnpayTask.php";
		}
		myDemand(phpUrl);
	});
});

$(function(){
	$("#waitpayList li").click(function(){
		var type=$(this).html();
		var phpUrl;
		if(type=="全部任务"){
			phpUrl="selectAllTask2.php";
		}else if(type=="待确认"){
			phpUrl="selectUnconfirmTask2.php";
		}else if(type=="待完成"){
			phpUrl="selectDoingTask2.php";
		}
		myDemand(phpUrl);
	});
});

function myDemand(phpUrl){
	$.ajax({
		type:"POST",
		url:"http://123.207.114.241/fishCow/php/"+phpUrl,
		dataType:"json",
		data:{
			id:theUser
		},
		success:function(x,y,z){
			var list=$("#messageList ul");
			list.empty();
			var a;
			if(x.length==0){
				list.append('<li class="nomessage">暂无信息>_<....</li>');
			}else{
				for(n=0;n<x.length;n++){
					if(!x[n].nenufish_skillFind_pay){
						a=x[n].nenufish_skillFind_payType
					}else{
						a=x[n].nenufish_skillFind_pay+"元";
					}
					list.append(
						'<li>'+
						'<div>标题:'+x[n].nenufish_skillFind_title+'</div>'
						+'<div>发布时间:'+x[n].nenufish_skillFind_datatime+'</div>'
						+'<div>技能分类:'+x[n].nenufish_skillFind_type+'</div>'
						+'<div>报酬:'+a+'</div>'
						+'<div><span>技能要求:</span><span>'+x[n].nenufish_skillFind_content+'</span></div>'
						+'<div>时间限制:'+x[n].nenufish_skillFind_time+'天</div>'
						+'<div>QQ:'+x[n].nenufish_skillFind_qq+'</div>'
						+'<div>电话:'+x[n].nenufish_skillFind_phone+'</div>'
						+'<div class="submitForm">'
						+'<button class=" ui-btn ui-shadow ui-corner-all">举报</button>'
						+'</div>'
						+'</li>'
					);
				}
			}
		},
		error:function(jqXHR){
		    alert("发生错误:"+jqXHR.status);
		}
	});
}